package com.cz.nongyetongv5.activity;

import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.location.Location;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.GridView;
import android.widget.PopupWindow;
import android.widget.TextView;
import android.widget.Toast;

import com.amap.api.location.AMapLocation;
import com.amap.api.location.AMapLocationListener;
import com.amap.api.location.LocationManagerProxy;
import com.amap.api.location.LocationProviderProxy;
import com.cz.nongyetongv5.R;
import com.cz.nongyetongv5.adapter.PhotoGrideAdapter;
import com.cz.nongyetongv5.adapter.cache.CommonUtil;
import com.cz.nongyetongv5.application.InitApplication;
import com.cz.nongyetongv5.bean.Photo;
import com.cz.nongyetongv5.custom.dialog.CustomDialog;
import com.cz.nongyetongv5.custom.wheelview.Utils;
import com.cz.nongyetongv5.utils.CharsetUtil;
import com.cz.nongyetongv5.utils.DialogUtil;
import com.cz.nongyetongv5.utils.GoHomeUtil;
import com.cz.nongyetongv5.utils.HttpUtils;
import com.cz.nongyetongv5.utils.HttpUtils.OnRequestExecuted;
import com.cz.nongyetongv5.utils.ImageUtil;
import com.umeng.analytics.MobclickAgent;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.File;
import java.io.IOException;
import java.io.Serializable;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;

//  µœ÷∏ﬂµ¬∂®ŒªµƒΩ”ø⁄
public class PaiZhaoActivity extends Activity implements OnClickListener,
        AMapLocationListener {

    /**
     * Õº±Í≤ºæ÷
     */
    private GridView gvPhoto = null;

    /**
     * ∑µªÿ∞¥≈•
     */
    private ViewGroup btnBack = null;

    /**
     * À˘”–’’∆¨ ˝æ›
     */
    private List<Photo> photos = null;

    /**
     * √ø¥Œ≈ƒ’’µƒ∂‘œÛ
     */
    private File photo = null;

    /**
     * ≈ƒ’’µƒ«Î«Û±‡¬Î
     */
    private static final int REQUEST_PHOTO_CODE = 0;

    /**
     * ¥ÛÕºµƒ—˘ Ω
     */
    public static final int REQUEST_DETAIL_PHOTO_CODE = 1;

    /**
     * ∏ﬂµ¬µÿÕºµƒ∂®Œª Ù–‘
     */
    private LocationManagerProxy mAMapLocManager = null;


    /**
     * ∏ﬂµ¬µÿÕºµƒ∂®Œª–≈œ¢∂‘œÛ
     */
    private AMapLocation location = null;

    /*
     * ¥´µ›π˝¿¥µƒ±ÍÃ‚
     */
    private String title = null;


    /**
     * «Â¿Ì∏ﬂµ¬µÿÕºµƒ◊ ‘¥
     */
    @Override
    protected void onDestroy() {

        InitApplication initApplication = (InitApplication) getApplicationContext();
        initApplication.getActivities().remove(this);
        if (mAMapLocManager != null) {
            mAMapLocManager.removeUpdates(this);
            mAMapLocManager.destory();
        }
        mAMapLocManager = null;
        super.onDestroy();
    }

    @Override
    protected void onResume() {
        System.out.println("onResume");
        super.onResume();
        MobclickAgent.onResume(this);

		/*
         * ≥ı ºªØ∏ﬂµ¬µÿÕºµƒ∂®Œª∂‘œÛ
		 */
        mAMapLocManager = LocationManagerProxy.getInstance(this);
        /*
         * mAMapLocManager.setGpsEnable(false);//
		 * 1.0.2∞Ê±æ–¬‘ˆ∑Ω∑®£¨…Ë÷√true±Ì æªÏ∫œ∂®Œª÷–∞¸∫¨gps∂®Œª£¨false±Ì æ¥øÕ¯¬Á∂®Œª£¨ƒ¨»œ «true Location
		 * API∂®Œª≤…”√GPS∫ÕÕ¯¬ÁªÏ∫œ∂®Œª∑Ω Ω
		 * £¨µ⁄“ª∏ˆ≤Œ ˝ «∂®Œªprovider£¨µ⁄∂˛∏ˆ≤Œ ˝ ±º‰◊Ó∂Ã «5000∫¡√Î£¨µ⁄»˝∏ˆ≤Œ ˝æ‡¿Îº‰∏Ùµ•Œª «√◊£¨µ⁄Àƒ∏ˆ≤Œ ˝ «∂®Œªº‡Ã˝’ﬂ
		 */
        mAMapLocManager.requestLocationUpdates(
                LocationProviderProxy.AMapNetwork, 1500, 10, this);

    }

    @Override
    protected void onPause() {
        System.out.println("onPause");
        super.onPause();
        if (mAMapLocManager != null) {
            mAMapLocManager.removeUpdates(this);
            mAMapLocManager.destory();
        }
        mAMapLocManager = null;
        MobclickAgent.onPause(this);

    }

    /**
     * µ±∑µªÿµƒ ±∫Ú
     */
    private void doBack() {
        if (photos != null) {
            if (photos.size() > 0
                    && photos.get(photos.size() - 1).getSmallPhotoPath() instanceof Integer) {
                photos.remove(photos.size() - 1);
            }
        }

        Intent return_photodata = new Intent();

        return_photodata.putExtra("photos", (Serializable) photos);

        setResult(JianDuJianChaNewRecordActivity.PAIZHAO_REQUEST_CODE,
                return_photodata);

        finish();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        System.out.println("onCreate");
        InitApplication initApplication = (InitApplication) getApplicationContext();

        initApplication.getActivities().add(this);

        setContentView(R.layout.paizhao);
        //        if (savedInstanceState != null) {
        //            photo = new File(savedInstanceState.getString("photo"));
        //        }
        initView();

        initConfig();

        loadRightTitle();

    }

    private String type = "";

    /**
     * º”‘ÿ»•÷˜“≥µƒ∞¥≈•
     */
    public void loadRightTitle() {

        ViewGroup btnMeanMore = (ViewGroup) findViewById(R.id.btnMeanMore);
        ((TextView) this.findViewById(R.id.btnMoreTxt)).setText("确定");
        View view = GoHomeUtil.createPopView(getApplicationContext(),
                new String[]{"主页"});

        // µØ≥ˆ∏¸∂‡µƒ≤Àµ•
        final PopupWindow pop = new PopupWindow(view,
                LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, false);

        // –Ë“™…Ë÷√“ªœ¬¥À≤Œ ˝£¨µ„ª˜Õ‚±ﬂø…œ˚ ß
        pop.setBackgroundDrawable(new BitmapDrawable());

        // …Ë÷√µ„ª˜¥∞ø⁄Õ‚±ﬂ¥∞ø⁄œ˚ ß
        pop.setOutsideTouchable(true);

        // …Ë÷√¥À≤Œ ˝ªÒµ√Ωπµ„£¨∑Ò‘ÚŒﬁ∑®µ„ª˜
        pop.setFocusable(true);

        final Button btn01 = (Button) pop.getContentView().findViewWithTag(
                "btn0");

        OnClickListener menuOnClick = new OnClickListener() {

            @Override
            public void onClick(View v) {

                if (v == btn01) {
                    GoHomeUtil.goHome(getApplicationContext());
                }
            }
        };

        btn01.setOnClickListener(menuOnClick);

        btnMeanMore = (ViewGroup) findViewById(R.id.btnMeanMore);

        btnMeanMore.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                doBack();
                //
                //				if (pop.isShowing()) {
                //					// “˛≤ÿ¥∞ø⁄£¨»Áπ˚…Ë÷√¡Àµ„ª˜¥∞ø⁄Õ‚–° ±º¥≤ª–Ë“™¥À∑Ω Ω“˛≤ÿ
                //					pop.dismiss();
                //				} else {
                //					// œ‘ æ¥∞ø⁄
                //					pop.showAsDropDown(v);
                //				}

            }
        });

    }

    private void initView() {
        /**
         * º”‘ÿ∑µªÿ∞¥≈•
         */
        btnBack = (ViewGroup) findViewById(R.id.btnBack);

        btnBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                doBack();
            }
        });

        /**
         */
        gvPhoto = (GridView) findViewById(R.id.gvPhotoLayout);

    }

    private void initConfig() {

        Intent data = getIntent();

        if (data != null && data.getExtras() != null) {

            photos = (List<Photo>) data.getExtras().getSerializable("photos");

            if (photos != null) {

                // ≥ı ºªØ∏¸∂‡∞¥≈•
                Photo btn_more = new Photo();

                btn_more.setSmallPhotoPath(R.drawable.gengduo_icon_btn_press_style);

                photos.add(btn_more);

                /**
                 * ≥ı ºªØ–°Õº ˝æ›
                 */
                PhotoGrideAdapter photoGridAdapter = new PhotoGrideAdapter(
                        this, photos, getLayoutInflater(), this);

                gvPhoto.setAdapter(photoGridAdapter);

            }

            // »Áπ˚√ª”–’’∆¨ ˝æ›‘Ú÷±Ω”¥Úø™œ‡ª˙≈ƒ…„≥Ã–Ú
            if (photos.size() < 2) {
                doPhoto();
            }

            title = data.getExtras().getString("title");
            try {
                type = data.getExtras().getString("type");
            } catch (java.lang.Exception e) {


            }
            if (CharsetUtil.isNotNull(title)) {

                TextView tvTitle = (TextView) findViewById(R.id.tvTitle);

                tvTitle.setText(title);
            }

        }

    }

    // µ±≈ƒ’’≥…π¶µƒ ±∫Ú∑µªÿ ˝æ›
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if (requestCode == REQUEST_PHOTO_CODE
                && resultCode == Activity.RESULT_OK) {

            /**
             * Õº∆¨µƒ∂‘œÛ
             */
            final Photo image = new Photo();

            // µ±≈ƒ’’≥…π¶∑µªÿµƒ ±∫ÚºÏ≤‚÷∏∂®wei
            // if (photo != null && photo.exists()) {
            if (photo != null) {
                new AsyncTask<Integer, Integer, Integer>() {

                    /**
                     * ◊‘∂®“Âµ»¥˝øÚ
                     */
                    private CustomDialog progressDialog = null;

                    protected void onPreExecute() {

                        progressDialog = new CustomDialog(PaiZhaoActivity.this);

                        progressDialog.setMessage("正在处理图片...");

                        progressDialog.setCanceledOnTouchOutside(false);

                        progressDialog.setWidthPercent(0.6F);

                        progressDialog.setTitle(null);

                        progressDialog.setActionTxt(null);

                        progressDialog.setCancleTxt(null);

                        progressDialog.showWait();

                    }

                    @Override
                    protected Integer doInBackground(Integer... params) {

                        Calendar time = null;

                        URL url = null;
                        URLConnection uc = null;
                        try {
                            url = new URL("http://www.baidu.com/");// »°µ√◊ ‘¥∂‘œÛ
                            uc = url.openConnection();// …˙≥…¡¨Ω”∂‘œÛ
                            uc.connect(); // ∑¢≥ˆ¡¨Ω”
                            long milliseconds = uc.getDate(); // »°µ√Õ¯’æ»’∆⁄ ±º‰

                            time = new GregorianCalendar();
                            time.setTimeInMillis(milliseconds);

                        } catch (MalformedURLException e) {
                        } catch (IOException e) {
                        }

                        if (time == null) {
                            // …Ë÷√√ª”–Õ¯¬Á
                            image.setNoNetwork(true);

                            // …Ë÷√±æµÿ ±º‰
                            time = new GregorianCalendar();
                        }

                        // …Ë÷√≈ƒ…„ ±º‰
                        image.setPhotoTime(new SimpleDateFormat(
                                "yyyy-MM-dd HH:mm:ss").format(time.getTime()));

                        int height = getWindowManager().getDefaultDisplay()
                                .getHeight();

                        int width = getWindowManager().getDefaultDisplay()
                                .getWidth();

                        // // Ω¯––Õº∆¨µƒ—πÀı
                        // Bitmap photoImage = ImageUtil
                        // .decodeSampledBitmapFromResource(
                        // photo.getAbsolutePath(), width, height
                        // - (height / 4));

                        // // Ω¯––Õº∆¨µƒ—πÀı
                        Bitmap photoImage = ImageUtil
                                .decodeSampledBitmapFromResource(
                                        photo.getAbsolutePath(), 480, 800);


                        //                        int degree = ImageUtil.readPictureDegree(photo
                        //                                .getAbsolutePath());
                        //                        System.out.println(degree);
                        //
                        //                        photoImage = ImageUtil.rotaingImageView(degree,
                        //                                photoImage);

                        // ±£¥ÊàD
                        ImageUtil.bigmapSave(photo, photoImage, 25);

                        // –°Õºµƒ±£¥Ê¬∑æ∂
                        File saveSmallPhotoDir = new File(
                                ImageUtil.getStoragePath(),
                                ("nongyetong" + File.separator + "photo"
                                        + File.separator + "xiaotu" + File.separator));

                        // ¥¥Ω®–°ÕºŒƒº˛¬∑æ∂
                        ImageUtil.makeDir(saveSmallPhotoDir);

                        // –°ÕºŒƒº˛√˚≥∆
                        String fileName = new SimpleDateFormat("yyMMddHHmmss")
                                .format(new Date()) + ".jpg";

                        // –°ÕºŒƒº˛
                        File smallSavePhoto = new File(saveSmallPhotoDir,
                                fileName);

                        // –°ÕºµƒøÌ∏ﬂ
                        int smallPhotoWidOrHei = Utils.dip2px(
                                PaiZhaoActivity.this, 80);

                        // —πÀı≥ˆ¿¥µƒ–°Õ√
                        Bitmap smallPhoto = ImageUtil
                                .decodeSampledBitmapFromResource(
                                        photo.getAbsolutePath(),
                                        smallPhotoWidOrHei, smallPhotoWidOrHei);

                        // ±£¥Ê–°ÕºŒƒº˛
                        ImageUtil.bigmapSave(smallSavePhoto, smallPhoto, 25);

                        // …Ë÷√–°Õº
                        image.setSmallPhotoPath(smallSavePhoto
                                .getAbsolutePath());

                        // …Ë÷√¥ÛÕº
                        image.setBigPhotoPath(photo.getAbsolutePath());

                        // «Â¿Ì–°Õº
                        smallPhoto.recycle();

                        photoImage.recycle();

                        // ∂®Œª–≈œ¢≤ªŒ™ø’
                        if (location != null) {
                            // Œ¨∂»
                            final double latitude = (double) (Math.round(location.getLatitude() * 1000000) / 1000000.0);

                            // æ´∂»
                            final double longitude = (double) (Math.round(location.getLongitude() * 1000000) / 1000000.0);

                            // µÿ÷∑√Ë ˆ
                            String desc = "";


                            Bundle locBundle = location.getExtras();

                            if (locBundle != null) {
                                desc = locBundle.getString("desc");
                            }
                            // …Ë÷√µÿ«¯–≈œ¢
                            image.setAddressDesc(desc);

                            if (CommonUtil.checkNetState(PaiZhaoActivity.this)) {
                                new AsyncTask<Integer, Integer, Integer>() {
                                    private int responseCodeRet;

                                    @Override
                                    protected Integer doInBackground(
                                            Integer... params) {
                                        String json = null;
                                        try {
                                            JSONObject jsonObject = new JSONObject();
                                            jsonObject.put("coords", latitude
                                                    + "," + longitude);
                                            json = jsonObject.toString();
                                        } catch (JSONException e) {
                                            e.printStackTrace();
                                        }
                                        String requestUrl = getString(R.string.change_gaodetobaidu)
                                                + "&coords=+"
                                                + latitude
                                                + ","
                                                + longitude;
                                        HttpUtils httpUtils = HttpUtils
                                                .getInstance();
                                        httpUtils
                                                .setOnRequestExecuted(new OnRequestExecuted() {
                                                    @Override
                                                    public void onRequestExecuted(
                                                            int responseCode,
                                                            String responseBody) {
                                                        responseCodeRet = responseCode;
                                                        if (responseCodeRet == HttpUtils.SUCCESS) {
                                                            try {
                                                                JSONObject dataJson = new JSONObject(
                                                                        responseBody);
                                                                JSONObject resultJson = new JSONObject(
                                                                        dataJson.getJSONArray(
                                                                                "result")
                                                                                .get(0)
                                                                                .toString());
                                                                // …Ë÷√Œ≥∂»
                                                                image.setLatitude(resultJson
                                                                        .getDouble("x"));
                                                                // …Ë÷√æ´∂»
                                                                image.setLongitude(resultJson
                                                                        .getDouble("y"));

                                                            } catch (JSONException e) {
                                                                // TODO
                                                                // Auto-generated
                                                                // catch block
                                                                e.printStackTrace();
                                                            }
                                                        }
                                                    }
                                                });
                                        httpUtils.sendRequest(requestUrl, null,
                                                "GET", "UTF-8", null, null,
                                                null);
                                        return null;
                                    }

                                    protected void onPostExecute(Integer result) {
                                        switch (responseCodeRet) {
                                            case HttpUtils.TIMEOUT:
                                            case HttpUtils.UNKNOWERROR:
                                                DialogUtil.showMessageDialog(
                                                        "经纬度获取失败,请重新拍照", null,
                                                        PaiZhaoActivity.this);
                                                break;
                                        }
                                    }

                                    ;
                                }.execute();
                            } else {
                                DialogUtil.showMessageDialog(
                                        getString(R.string.error_no_network),
                                        null, PaiZhaoActivity.this);
                            }

                        } else {
                            if (InitApplication.photolat != null) {
                                image.setLatitude(InitApplication.photolat);
                                image.setLongitude(InitApplication.photolng);
                                image.setAddressDesc(InitApplication.organization);
                            } else {
                                image.setLatitude((double) 0);
                                image.setLongitude((double) 0);
                                image.setAddressDesc("未知");
                            }
                        }

                        image.setUpload(true);
                        // Ω´–≈œ¢‘ˆº”µΩ ˝æ›÷–
                        photos.add(photos.size() - 1, image);

                        return null;
                    }

                    protected void onPostExecute(Integer result) {

                        if (progressDialog != null) {
                            progressDialog.dismiss();

                            if (gvPhoto.getAdapter() instanceof PhotoGrideAdapter) {

                                PhotoGrideAdapter adapter = (PhotoGrideAdapter) gvPhoto
                                        .getAdapter();

                                adapter.notifyDataSetChanged();

                            }
                        }
                    }

                    ;

                }.execute();

            } else {
                Toast.makeText(PaiZhaoActivity.this, "获取图片失败", Toast.LENGTH_LONG).show();
            }
        } else if (requestCode == REQUEST_DETAIL_PHOTO_CODE) {
            // »Áπ˚ «¥”¥ÛÕº“≥√Ê∑µªÿµƒ
            if (data != null) {

                // ª÷∏¥∏¸∂‡∞¥≈•
                Photo btn_more = photos.get(photos.size() - 1);

                photos = (List<Photo>) data.getExtras().get("photos");

                photos.add(btn_more);

                // À¢–¬ΩÁ√Ê

                if (gvPhoto.getAdapter() instanceof PhotoGrideAdapter) {

                    PhotoGrideAdapter adapter = (PhotoGrideAdapter) gvPhoto
                            .getAdapter();

                    adapter.setPhotoGridData(photos);

                }

            }

        }

    }

    /*
     * ∆Ù∂Ø≈ƒ’’
     */
    private void doPhoto() {
        // ∆Ù∂Ø≈ƒ’’
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

        intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
        intent.putExtra(MediaStore.EXTRA_SCREEN_ORIENTATION,
                ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);

        if (ImageUtil.hasStore()) {

            // ªÒµ√¥Ê¥¢ø®µƒ¬∑æ∂
            String storePath = ImageUtil.getStoragePath().getAbsolutePath();

            // ‘≠Õºµƒ±£¥Ê¬∑æ∂
            File savePhotoDir = new File(storePath,
                    ("nongyetong" + File.separator + "photo" + File.separator
                            + "yuantu" + File.separator));

            // ¥¥Ω®Œƒº˛¬∑æ∂
            ImageUtil.makeDir(savePhotoDir);

            // Œƒº˛√˚≥∆
            String fileName = new SimpleDateFormat("yyMMddHHmmss")
                    .format(new Date()) + ".jpg";

            // ±£¥ÊµƒŒƒº˛∂‘œÛ
            photo = new File(savePhotoDir, fileName);

            //  ‰»ÎµΩ÷∆∂®µƒŒƒº˛ƒø¬ºœ¬
            Uri uri = Uri.fromFile(photo);

            intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);

            startActivityForResult(intent, REQUEST_PHOTO_CODE);

        } else {
            Toast.makeText(PaiZhaoActivity.this, "未检测到存储卡", Toast.LENGTH_LONG)
                    .show();

            return;
        }
    }

    @Override
    public void onClick(View v) {

        int position = gvPhoto.getPositionForView(v);

        // µ„ª˜≈ƒ’’µƒ ±∫Ú
        if (position == gvPhoto.getAdapter().getCount() - 1) {
            doPhoto();
        } else {

            // ∆Ù∂ØœÍœ∏’’∆¨“≥
            Intent to_detailphoto_intent = new Intent(this,
                    PhotoDetailActivity.class);

            // ¥´µ›’’∆¨ ˝æ›
            to_detailphoto_intent.putExtra("photos", (Serializable) photos);
            to_detailphoto_intent.putExtra("type", type);
            // µ„ª˜ÕºœÒµƒœ¬±Í
            to_detailphoto_intent.putExtra("click_photo_index", position);

            startActivityForResult(to_detailphoto_intent,
                    REQUEST_DETAIL_PHOTO_CODE);
        }
    }

    /**
     * µ±µÿ÷∑∏ƒ±‰µƒ ±∫Ú,¥À∑Ω∑®“—æ≠∑œ∆˙
     */
    @Override
    public void onLocationChanged(Location location) {
    }

    @Override
    public void onProviderDisabled(String provider) {
    }

    @Override
    public void onProviderEnabled(String provider) {
    }

    @Override
    public void onStatusChanged(String provider, int status, Bundle extras) {
    }

    /**
     * µ±µÿ÷∑∏ƒ±‰µƒ ±∫Ú
     */
    @Override
    public void onLocationChanged(AMapLocation location) {


        //                System.out.println(location.getLatitude()+location.getLongitude()+location.getCity()+"dddddddd");
        if (location != null) {
            this.location = location;




			/*
             * ∏ﬂµ¬µÿÕºµƒ∂®Œª∞∏¿˝ Double geoLat = location.getLatitude(); Double geoLng =
			 * location.getLongitude(); String cityCode = ""; String desc = "";
			 * Bundle locBundle = location.getExtras(); if (locBundle != null) {
			 * cityCode = locBundle.getString("citycode"); desc =
			 * locBundle.getString("desc"); }
			 *
			 * String str = ("∂®Œª≥…π¶:(" + geoLng + "," + geoLat + ")" +
			 * "\næ´    ∂»    :" + location.getAccuracy() + "√◊" + "\n∂®Œª∑Ω Ω:" +
			 * location.getProvider() + "\n∂®Œª ±º‰:" + "\n≥« –±‡¬Î:" + cityCode +
			 * "\nŒª÷√√Ë ˆ:" + desc + "\n °:" + location.getProvince() + "\n –:" +
			 * location.getCity() + "\n«¯(œÿ):" + location.getDistrict() +
			 * "\n«¯”Ú±‡¬Î:" + location .getAdCode());
			 *
			 * Toast.makeText(PaiZhaoActivity.this, str,
			 * Toast.LENGTH_SHORT).show();
			 */

        }
    }

    @Override
    public void onBackPressed() {

        if (photos != null) {

            if (photos.size() > 0
                    && photos.get(photos.size() - 1).getSmallPhotoPath() instanceof Integer) {
                photos.remove(photos.size() - 1);
            }

        }

        Intent return_photodata = new Intent();

        return_photodata.putExtra("photos", (Serializable) photos);

        setResult(JianDuJianChaNewRecordActivity.PAIZHAO_REQUEST_CODE,
                return_photodata);
        //        setResult(RESULT_OK,
        //                return_photodata);


        finish();

    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        //        outState.putString("photo", photo.getAbsolutePath());
        super.onSaveInstanceState(outState);
    }


    @Override
    protected void onStart() {
        System.out.println("onStart");
        super.onStart();
    }

    @Override
    protected void onRestart() {
        System.out.println("onRestart");
        super.onRestart();
    }


    @Override
    protected void onStop() {
        System.out.println(" onStop");
        super.onStop();
    }


}
